package com.briup.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.demo.bean.CmsLink;
import com.briup.demo.common.Response;
import com.briup.demo.service.CmsLinkService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "链接管理")
@RestController
@RequestMapping("/link")
public class CmsLinkController {

	@Autowired
	private CmsLinkService linkService;
	
	@ApiOperation(value = "删除链接")
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(int id){
		int num = linkService.deleteById(id);
		if(num == 1) {
			return Response.ok("删除成功");
		}else {
			return Response.ok("删除失败");
		}
		
	}
	
	@ApiOperation(value = "批量删除链接")
	@DeleteMapping("/deleteByIds")
	public Response<String> deleteById(int[] ids){
		int num = linkService.deleteByIds(ids);
		return Response.ok("删除成功"+num+"条链接");
		
	}
	
	@ApiOperation(value = "查找所链接")
	@GetMapping("/selectAll")
	public Response<List<CmsLink>> selectAll(){
		List<CmsLink> cl = linkService.selectAll();
		return Response.ok(cl);
	}
	
    @ApiOperation(value = "保存或更新链接")
    @PostMapping("/saveOrUpdate")
    public Response<String > saveOrUpdate(CmsLink link){
    	linkService.saveOrUpdate(link);
    	return Response.ok("操作成功");
    }
}
